<?php
require("./common.php");
include S_ROOT."include/image.class.php";
include(S_ROOT."data/dataconfig.php");

//print_r($_POST);
//
//print_r($_FILES);

$fileurl = $_FILES['Filedata'];

if (!$fileurl['name']) {
	$fileurl = array();
}
if (empty($fileurl['name'])) {
	echo 'Error:请上传图片';
}
if (!empty($fileurl)) {
	if ($fileurl['error'] !== 0) {
		echo 'Error:上传图片发生错误';
	}else {
		$extname = fileext($fileurl['name']);
		$allow = array('jpg','jpeg','gif','png','tif','bmp');
		if(!in_array($extname,$allow)) {
			echo 'Error:请上传以'.join(',',$allow)."结尾的图片！";
		}
		$fileName  = 'upload/img/'.md5(time());
		$uploadurl = $fileName.'.'.$extname;
		$thumbUrl  = $fileName.'_thumb.'.$extname;
		move_uploaded_file($fileurl['tmp_name'],S_ROOT.$uploadurl);
		$tp = new image();
		$tp->thumb(S_ROOT.$uploadurl,S_ROOT.$thumbUrl,$_CONFIG['thumbwidth'],$_CONFIG['thumbheight']);
		$data['imageurl'] =  $uploadurl;
		$data['thumburl'] =  $thumbUrl;
		echo "Success:$uploadurl|$thumbUrl";
	}
}
?>